﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/Admin-One-Column.master" AutoEventWireup="true" CodeBehind="HoaDon.aspx.cs" Inherits="BookStore.admin.HoaDon" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="BreadcrumbsContent" runat="server">
<h1>Chi Tiết Thông Tin Hóa Đơn</h1>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainColumnContent" runat="server">
<div id="admin-table">
    <asp:Label ID="aaa" runat="server" Text="Label"></asp:Label>
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        CellPadding="4" DataKeyNames="MaHD" DataSourceID="SqlDataSource1" 
        ForeColor="#333333" GridLines="None" Height="50px" Width="332px" 
        Style="float:left;" oniteminserted="DetailsView1_ItemInserted" >
        <AlternatingRowStyle BackColor="White" />
        <CommandRowStyle BackColor="#C5BBAF" Font-Bold="True" />
        <EditRowStyle BackColor="#7C6F57" />
        <FieldHeaderStyle BackColor="#D0D0D0" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="MaHD" HeaderText="MaHD" InsertVisible="False" 
                ReadOnly="True" SortExpression="MaHD" />
            <asp:TemplateField HeaderText="MaKH" SortExpression="MaKH">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="KH_DS" SelectedValue='<%# Bind("MaKH") %>'
                            DataTextField="TenKhachHang" DataValueField="MaKhachHang">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="KH_DS" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
                            SelectCommand="SELECT [MaKhachHang], [TenKhachHang] FROM [KhachHang]">
                        </asp:SqlDataSource>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="KH_DS" SelectedValue='<%# Bind("MaKH") %>'
                            DataTextField="TenKhachHang" DataValueField="MaKhachHang">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="KH_DS" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
                            SelectCommand="SELECT [MaKhachHang], [TenKhachHang] FROM [KhachHang]">
                        </asp:SqlDataSource>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList2" Enabled="false" runat="server" DataSourceID="KH_DS" SelectedValue='<%# Bind("MaKH") %>'
                            DataTextField="TenKhachHang" DataValueField="MaKhachHang">
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="KH_DS" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
                            SelectCommand="SELECT [MaKhachHang], [TenKhachHang] FROM [KhachHang]">
                        </asp:SqlDataSource>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="DiaChiHoaDon" SortExpression="DiaChiHoaDon">
                <EditItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox2" runat="server" Text='<%# Bind("DiaChiHoaDon") %>' TextMode="MultiLine" ></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox2" runat="server" Text='<%# Bind("DiaChiHoaDon") %>' TextMode="MultiLine" ></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("DiaChiHoaDon") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="DiaChiGiaoHang" SortExpression="DiaChiGiaoHang">
                <EditItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox1" runat="server" Text='<%# Bind("DiaChiGiaoHang") %>' TextMode="MultiLine" ></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox CssClass="input-text" ID="TextBox1" runat="server" Text='<%# Bind("DiaChiGiaoHang") %>' TextMode="MultiLine" ></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("DiaChiGiaoHang") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="SoDT" HeaderText="SoDT" 
                SortExpression="SoDT" >
            <ControlStyle CssClass="input-text" />
            </asp:BoundField>
            <asp:BoundField DataField="NgayThang" HeaderText="NgayThang" 
                SortExpression="NgayThang" >
            <ControlStyle CssClass="input-text" />
            </asp:BoundField>
            <asp:TemplateField HeaderText="TrangThai" SortExpression="TrangThai">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" SelectedValue='<%# Bind("TrangThai") %>' runat="server">
                            <asp:ListItem Value="0">Chưa giao hàng</asp:ListItem>
                            <asp:ListItem Value="1">Đã Giao</asp:ListItem>
                        </asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList1" SelectedValue='<%# Bind("TrangThai") %>' runat="server">
                            <asp:ListItem Value="0">Chưa giao hàng</asp:ListItem>
                            <asp:ListItem Value="1">Đã Giao</asp:ListItem>
                        </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" SelectedValue='<%# Bind("TrangThai") %>' runat="server"
                            Enabled="false">
                            <asp:ListItem Value="0">Chưa giao hàng</asp:ListItem>
                            <asp:ListItem Value="1">Đã Giao</asp:ListItem>
                        </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text=""><img alt="Delete" src="../images/check.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Insert" Text=""><img alt="Insert" src="../images/add.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                        Text=""><img alt="Edit" src="../images/pencil.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="New"
                        Text=""><img alt="Insert" src="../images/add.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandName="Delete"
                        Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Fields>
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" />
    </asp:DetailsView>
    <div class="right" style="margin-right:230px;">
        <asp:GridView ID="CTHD_GV" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="MaHD,MaSach" DataSourceID="CTHD_GVDS" AllowPaging="True" 
            ShowHeaderWhenEmpty="True">
            <AlternatingRowStyle CssClass="alt-row" />
            <HeaderStyle BackColor="#F3F3F3" />
            <Columns>
                <asp:BoundField DataField="MaSach" HeaderText="Sách" ReadOnly="True" 
                    SortExpression="MaSach" />
                <asp:BoundField DataField="DonGia" HeaderText="Đơn Giá" 
                    SortExpression="DonGia" >
                <ControlStyle CssClass="input-text" />
                </asp:BoundField>
                <asp:BoundField DataField="SoLuong" HeaderText="Số Lượng" 
                    SortExpression="SoLuong" >
                <ControlStyle CssClass="input-text" />
                </asp:BoundField>
                <asp:BoundField DataField="TongGia" HeaderText="Tổng" 
                    SortExpression="TongGia" >
                <ControlStyle CssClass="input-text" />
                </asp:BoundField>
               <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" Text=""><img alt="Delete" src="../images/check.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text=""><img alt="Edit" src="../images/pencil.png"></asp:LinkButton>
                    &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text=""><img alt="Delete" src="../images/cross.png"></asp:LinkButton>
                </ItemTemplate>
                <ItemStyle Width="45px" />
            </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="CTHD_GVDS" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
            DeleteCommand="DELETE FROM [ChiTietHoaDon] WHERE [MaHD] = @original_MaHD AND [MaSach] = @original_MaSach AND (([DonGia] = @original_DonGia) OR ([DonGia] IS NULL AND @original_DonGia IS NULL)) AND (([SoLuong] = @original_SoLuong) OR ([SoLuong] IS NULL AND @original_SoLuong IS NULL)) AND (([TongGia] = @original_TongGia) OR ([TongGia] IS NULL AND @original_TongGia IS NULL))" 
            InsertCommand="INSERT INTO [ChiTietHoaDon] ([MaHD], [MaSach], [DonGia], [SoLuong], [TongGia]) VALUES (@MaHD, @MaSach, @DonGia, @SoLuong, @TongGia)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [ChiTietHoaDon] WHERE ([MaHD] = @MaHD)" 
            UpdateCommand="UPDATE [ChiTietHoaDon] SET [DonGia] = @DonGia, [SoLuong] = @SoLuong, [TongGia] = @TongGia WHERE [MaHD] = @original_MaHD AND [MaSach] = @original_MaSach AND (([DonGia] = @original_DonGia) OR ([DonGia] IS NULL AND @original_DonGia IS NULL)) AND (([SoLuong] = @original_SoLuong) OR ([SoLuong] IS NULL AND @original_SoLuong IS NULL)) AND (([TongGia] = @original_TongGia) OR ([TongGia] IS NULL AND @original_TongGia IS NULL))">
            <DeleteParameters>
                <asp:Parameter Name="original_MaHD" Type="Int32" />
                <asp:Parameter Name="original_MaSach" Type="Int32" />
                <asp:Parameter Name="original_DonGia" Type="Int32" />
                <asp:Parameter Name="original_SoLuong" Type="Int32" />
                <asp:Parameter Name="original_TongGia" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="MaHD" Type="Int32" />
                <asp:Parameter Name="MaSach" Type="Int32" />
                <asp:Parameter Name="DonGia" Type="Int32" />
                <asp:Parameter Name="SoLuong" Type="Int32" />
                <asp:Parameter Name="TongGia" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter Name="MaHD" QueryStringField="MaHD" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="DonGia" Type="Int32" />
                <asp:Parameter Name="SoLuong" Type="Int32" />
                <asp:Parameter Name="TongGia" Type="Int32" />
                <asp:Parameter Name="original_MaHD" Type="Int32" />
                <asp:Parameter Name="original_MaSach" Type="Int32" />
                <asp:Parameter Name="original_DonGia" Type="Int32" />
                <asp:Parameter Name="original_SoLuong" Type="Int32" />
                <asp:Parameter Name="original_TongGia" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:FormView ID="CTHDmoi_DV" runat="server" DataKeyNames="MaHD,MaSach" DefaultMode="Insert"
            DataSourceID="CTHDMoiDS">
            <EditItemTemplate>
                MaHD:
                <asp:Label ID="MaHDLabel1" runat="server" Text='<%# Eval("MaHD") %>' />
                <br />
                MaSach:
                <asp:Label ID="MaSachLabel1" runat="server" Text='<%# Eval("MaSach") %>' />
                <br />
                DonGia:
                <asp:TextBox ID="DonGiaTextBox" runat="server" Text='<%# Bind("DonGia") %>' />
                <br />
                SoLuong:
                <asp:TextBox ID="SoLuongTextBox" runat="server" Text='<%# Bind("SoLuong") %>' />
                <br />
                TongGia:
                <asp:TextBox ID="TongGiaTextBox" runat="server" Text='<%# Bind("TongGia") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
            <h4>Thêm vào hóa đơn</h4>
            <br />
                <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("MaHD") %>' />
                Sách:
                <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="SachDS" SelectedValue='<%# Bind("MaSach") %>'
                    DataTextField="TenSach" DataValueField="MaSach">
                </asp:DropDownList>
                <asp:SqlDataSource ID="SachDS" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
                    SelectCommand="SELECT [MaSach], [TenSach] FROM [Sach]"></asp:SqlDataSource>
                <br />
                Đơn Giá:
                <asp:TextBox CssClass="input-text" ID="DonGiaTextBox" runat="server" Text='<%# Bind("DonGia") %>' />
                <br />
                Số Lượng:
                <asp:TextBox CssClass="input-text" ID="SoLuongTextBox" runat="server" Text='<%# Bind("SoLuong") %>' />
                <br />
                Tổng:
                <asp:TextBox CssClass="input-text" ID="TongGiaTextBox" runat="server" Text='<%# Bind("TongGia") %>' />
                <br /><br />
                <asp:LinkButton  ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert"></asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                MaHD:
                <asp:Label ID="MaHDLabel" runat="server" Text='<%# Eval("MaHD") %>' />
                <br />
                MaSach:
                <asp:Label ID="MaSachLabel" runat="server" Text='<%# Eval("MaSach") %>' />
                <br />
                DonGia:
                <asp:Label ID="DonGiaLabel" runat="server" Text='<%# Bind("DonGia") %>' />
                <br />
                SoLuong:
                <asp:Label ID="SoLuongLabel" runat="server" Text='<%# Bind("SoLuong") %>' />
                <br />
                TongGia:
                <asp:Label ID="TongGiaLabel" runat="server" Text='<%# Bind("TongGia") %>' />
                <br />
                <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                    CommandName="Edit" Text="Edit" />
                &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                    CommandName="Delete" Text="Delete" />
                &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                    CommandName="New" Text="New" />
            </ItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="CTHDMoiDS" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:BookStoreConnectionString %>" 
            DeleteCommand="DELETE FROM [ChiTietHoaDon] WHERE [MaHD] = @original_MaHD AND [MaSach] = @original_MaSach AND (([DonGia] = @original_DonGia) OR ([DonGia] IS NULL AND @original_DonGia IS NULL)) AND (([SoLuong] = @original_SoLuong) OR ([SoLuong] IS NULL AND @original_SoLuong IS NULL)) AND (([TongGia] = @original_TongGia) OR ([TongGia] IS NULL AND @original_TongGia IS NULL))" 
            InsertCommand="INSERT INTO [ChiTietHoaDon] ([MaHD], [MaSach], [DonGia], [SoLuong], [TongGia]) VALUES (@MaHD, @MaSach, @DonGia, @SoLuong, @TongGia)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT * FROM [ChiTietHoaDon] WHERE ([MaHD] = @MaHD)" 
            UpdateCommand="UPDATE [ChiTietHoaDon] SET [DonGia] = @DonGia, [SoLuong] = @SoLuong, [TongGia] = @TongGia WHERE [MaHD] = @original_MaHD AND [MaSach] = @original_MaSach AND (([DonGia] = @original_DonGia) OR ([DonGia] IS NULL AND @original_DonGia IS NULL)) AND (([SoLuong] = @original_SoLuong) OR ([SoLuong] IS NULL AND @original_SoLuong IS NULL)) AND (([TongGia] = @original_TongGia) OR ([TongGia] IS NULL AND @original_TongGia IS NULL))">
            <DeleteParameters>
                <asp:Parameter Name="original_MaHD" Type="Int32" />
                <asp:Parameter Name="original_MaSach" Type="Int32" />
                <asp:Parameter Name="original_DonGia" Type="Int32" />
                <asp:Parameter Name="original_SoLuong" Type="Int32" />
                <asp:Parameter Name="original_TongGia" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:QueryStringParameter Name="MaHD" QueryStringField="MaHD" Type="Int32" />
                <asp:Parameter Name="MaSach" Type="Int32" />
                <asp:Parameter Name="DonGia" Type="Int32" />
                <asp:Parameter Name="SoLuong" Type="Int32" />
                <asp:Parameter Name="TongGia" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter Name="MaHD" QueryStringField="MaHD" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="DonGia" Type="Int32" />
                <asp:Parameter Name="SoLuong" Type="Int32" />
                <asp:Parameter Name="TongGia" Type="Int32" />
                <asp:Parameter Name="original_MaHD" Type="Int32" />
                <asp:Parameter Name="original_MaSach" Type="Int32" />
                <asp:Parameter Name="original_DonGia" Type="Int32" />
                <asp:Parameter Name="original_SoLuong" Type="Int32" />
                <asp:Parameter Name="original_TongGia" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" 
        DeleteCommand="DELETE FROM [HoaDon] WHERE [MaHD] = @MaHD" 
        InsertCommand="INSERT INTO [HoaDon] ([MaKH], [DiaChiHoaDon], [DiaChiGiaoHang], [SoDT], [NgayThang], [TrangThai]) VALUES (@MaKH, @DiaChiHoaDon, @DiaChiGiaoHang, @SoDT, @NgayThang, @TrangThai)" 
        ProviderName="<%$ ConnectionStrings:ApplicationServices.ProviderName %>" 
        SelectCommand="SELECT [MaHD], [MaKH], [DiaChiHoaDon], [DiaChiGiaoHang], [SoDT], [NgayThang], [TrangThai] FROM [HoaDon] WHERE MaHD = @MaHD" 
        UpdateCommand="UPDATE [HoaDon] SET [MaKH] = @MaKH, [DiaChiHoaDon] = @DiaChiHoaDon, [DiaChiGiaoHang] = @DiaChiGiaoHang, [SoDT] = @SoDT, [NgayThang] = @NgayThang, [TrangThai] = @TrangThai WHERE [MaHD] = @MaHD">
        <SelectParameters>
            <asp:QueryStringParameter Name="MaHD"
                QueryStringField="MaHD" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="MaHD" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="MaKH" Type="Int32" />
            <asp:Parameter Name="DiaChiHoaDon" Type="String" />
            <asp:Parameter Name="DiaChiGiaoHang" Type="String" />
            <asp:Parameter Name="SoDT" Type="String" />
            <asp:Parameter Name="NgayThang" Type="DateTime" />
            <asp:Parameter Name="TrangThai" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="MaKH" Type="Int32" />
            <asp:Parameter Name="DiaChiHoaDon" Type="String" />
            <asp:Parameter Name="DiaChiGiaoHang" Type="String" />
            <asp:Parameter Name="SoDT" Type="String" />
            <asp:Parameter Name="NgayThang" Type="DateTime" />
            <asp:Parameter Name="TrangThai" Type="Int32" />
            <asp:Parameter Name="MaHD" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>
